#include <gtest/gtest.h>

using namespace ::std;

// 移除零类似，遍历，记录不等于指定值的元素个数，
// 并且把它挪到之前最后一个遍历到的非指定值的后面
class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
		int cntNonVal = 0;
		for(char n : nums) {
			if(n != val) {
				nums[cntNonVal++] = n;
			}
		}
		return cntNonVal;
    }
};

// v01
// class Solution {
// public:
//     int removeElement(vector<int>& nums, int val) {
// 		int cntNonVal = 0, size = nums.size();
// 		for(int i = 0; i < size; ++i) {
// 			if(nums[i] == val) continue;
// 			if(cntNonVal < i) nums[cntNonVal] = nums[i];
// 			cntNonVal++;
// 		}
// 		return cntNonVal;
//     }
// };

class RemoveElementCheck : public ::testing::Test {
public:
	class Solution solution;
};

TEST_F(RemoveElementCheck, testRemoveElement_1) {
	vector<int> nums({3, 2, 2, 3});
	int val = 3;
	EXPECT_TRUE(2 == solution.removeElement(nums, val));
}

TEST_F(RemoveElementCheck, testRemoveElement_2) {
	vector<int> nums({0,1,2,2,3,0,4,2});
	int val = 2;
	EXPECT_TRUE(5 == solution.removeElement(nums, val));
}

int main() {
	::testing::InitGoogleTest();
	return RUN_ALL_TESTS();
}
